﻿using Klear.Library.Models;

namespace Klear.Library.Services;

public class IncomeAndExpensesService : IIncomeAndExpensesService
{
    private static IDatabaseService _databaseService;
    
    public IncomeAndExpensesService(IDatabaseService databaseService)
    {
        _databaseService = databaseService;
    }
    
    //加载当月收支
    public async Task<IList<IncomeAndExpensesModel>> LoadIncomeAndExpensesAsync()
    {
        DateTime startTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
        DateTime endTime = startTime.AddMonths(1).AddTicks(-1);
        return await _databaseService.GetIncomeAndExpensesAsync(startTime, endTime);
    }
    //保存记录
    public async void SaveIncomeAndExpenses(IncomeAndExpensesModel data)
    {
        await _databaseService.AddRecordAsync(data);
    }
    //加载支出分类
    public async Task<IList<CategoryModel>> LoadExpensesAsync()
    {
        return await _databaseService.GetExpenseCategoriesAsync();
    }
    //加载收入分类
    public async Task<IList<CategoryModel>> LoadIncomeAsync()
    {
        return await _databaseService.GetIncomeCategoriesAsync();
    }
    
    //删除
    public async void Delete(IncomeAndExpensesModel data)
    {
        await _databaseService.Delete(data);
    }
}